package com.silence.gmall.web.controller;

import com.silence.gmall.base.Result;
import com.silence.gmall.web.feign.CategoryFeignClient;
import com.silence.gmall.web.vo.res.CategoryResVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @Author silence
 * @Date 2025-08-26 10:42
 * @Email 792245022@qq.com
 * @Version 1.0
 * @Description
 */
@Controller
@RequiredArgsConstructor
public class IndexController {

    /**
     * CategoryFeignClient 注入
     */
    private final CategoryFeignClient categoryFeignClient;

    /**
     * 登录
     *
     * @return 登录
     */
    @GetMapping({"/", "/index.html"})
    public String login(Model model) {
        Result<List<CategoryResVo>> result = categoryFeignClient.getCategoryTree();
        List<CategoryResVo> list = result.checkSuccess() ? result.getData() : List.of();
        model.addAttribute("list", list);
        return "index/index";
    }

}
